include:
  - local: .gitlab/ci/qa-common/main.gitlab-ci.yml
  - local: .gitlab/ci/qa-common/rules.gitlab-ci.yml
  - local: .gitlab/ci/qa-common/variables.gitlab-ci.yml

workflow:
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $SCHEDULE_TYPE == "nightly"'

.ce:
  variables:
    RELEASE: ${REGISTRY_HOST}/${REGISTRY_GROUP}/build/omnibus-gitlab-mirror/gitlab-ce:${CI_COMMIT_SHA}

.ee:
  variables:
    RELEASE: ${REGISTRY_HOST}/${REGISTRY_GROUP}/build/omnibus-gitlab-mirror/gitlab-ee:${CI_COMMIT_SHA}

# ==========================================
# Prepare stage
# ==========================================
trigger-omnibus-env:
  extends:
    - .trigger-omnibus-env

trigger-omnibus-env-ce:
  extends:
    - .trigger-omnibus-env-ce
  variables:
    FOSS_ONLY: "1"  # set FOSS_ONLY because we don't pass it via trigger job

trigger-omnibus:
  extends:
    - .trigger-omnibus
  needs:
    - trigger-omnibus-env

trigger-omnibus-ce:
  extends:
    - .trigger-omnibus-ce
  needs:
    - trigger-omnibus-env-ce

download-knapsack-report:
  extends:
    - .download-knapsack-report
    - .rules:download-knapsack

# ==========================================
# Test stage
# ==========================================

# ------------------------------------------
# Update jobs
# ------------------------------------------
update-ee-to-ce:
  extends:
    - .qa
    - .update-script
    - .ce
  variables:
    UPDATE_TYPE: minor
    UPDATE_FROM_EDITION: ee
    QA_RSPEC_TAGS: --tag smoke

# ------------------------------------------
# Network limiting jobs
# ------------------------------------------
airgapped:
  extends:
    - .qa
    - .ee
    - .parallel
  variables:
    QA_SCENARIO: "Test::Instance::Airgapped"
    QA_RSPEC_TAGS: "--tag '~github' --tag '~skip_live_env'"

instance-image-slow-network:
  extends:
    - .qa
    - .ee
    - .parallel
  variables:
    QA_SIMULATE_SLOW_CONNECTION: "true"

# ------------------------------------------
# N+1 jobs
# ------------------------------------------
nplus1-instance-image:
  extends:
    - .qa
    - .ee
    - .parallel
  variables:
    CACHE_NAMESPACE_NAME: "false"
    GITLAB_QA_OPTS: "--enable-feature gitaly_enforce_requests_limits"

# ------------------------------------------
# Elasticsearch compatibility jobs
# ------------------------------------------
integration-elasticsearch-compatibility-version-7:
  extends:
    - .qa
    - .ee
  variables:
    ELASTIC_VERSION: "7.17.0"
    QA_SCENARIO: "Test::Integration::Elasticsearch"

integration-elasticsearch-compatibility-version-8:
  extends:
    - .qa
    - .ee
  variables:
    ELASTIC_VERSION: "8.6.2"
    QA_SCENARIO: "Test::Integration::Elasticsearch"

# ------------------------------------------
# Opensearch compatibility jobs
# ------------------------------------------
integration-opensearch-compatibility-version-1:
  extends:
    - .qa
    - .ee
  variables:
    OPENSEARCH_VERSION: "1.3.3"
    QA_SCENARIO: "Test::Integration::Opensearch"

integration-opensearch-compatibility-version-2:
  extends:
    - .qa
    - .ee
  variables:
    OPENSEARCH_VERSION: "2.0.1"
    QA_SCENARIO: "Test::Integration::Opensearch"

# ------------------------------------------
# Remote browser jobs
# ------------------------------------------
remote-mobile-safari:
  extends:
    - .qa
    - .ee
  variables:
    QA_RSPEC_TAGS: "--tag mobile"
    QA_BROWSER: "safari"
    QA_REMOTE_MOBILE_DEVICE_NAME: "iPhone Simulator"
    QA_REMOTE_GRID: "ondemand.saucelabs.com:80"
    QA_REMOTE_TUNNEL_ID: "gitlab-sl_tunnel_id"
  before_script:
    - !reference [.qa, before_script]
    - docker pull saucelabs/sauce-connect
    - docker network create test
    - |
      docker run --detach \
        --network="test" \
        -e SAUCE_USERNAME=$QA_REMOTE_GRID_USERNAME \
        -e SAUCE_ACCESS_KEY=$QA_REMOTE_GRID_ACCESS_KEY \
        -t saucelabs/sauce-connect \
        -i $QA_REMOTE_TUNNEL_ID

# ==========================================
# Post test stage
# ==========================================
e2e-test-report:
  extends:
    - .e2e-test-report

upload-knapsack-report:
  extends:
    - .upload-knapsack-report

export-test-metrics:
  extends:
    - .export-test-metrics

relate-test-failures:
  extends:
    - .relate-test-failures

generate-test-session:
  extends:
    - .generate-test-session

notify-slack:
  extends:
    - .notify-slack
